﻿using System;
using System.Collections;
using System.Configuration;
using System.Data; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using System.Collections.Generic;
using System.Text;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;
using Runda.CMS.Workflow; 

namespace Runda.CMS.Portal.ContractManage
{
    public partial class ContractChangeEdit : WorkflowPage
    {
        public Guid ContractID
        {
            get
            {
                if (txtContractID.Value == "") return Guid.Empty;
                else return new Guid(txtContractID.Value);
            }
            set
            {
                txtContractID.Value = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
                if (Request.QueryString["OrginalContractID"] != null)
                {
                    ContractID = new Guid(Request.QueryString["OrginalContractID"]);
                    InitForm();
                } 
            }
        }

        private void InitForm()
        {
            CtrtContractEntity entity = new CtrtContractEntity();
            CtrtContractBll bll = new CtrtContractBll();

            if (ContractID != Guid.Empty)
            {
                entity = bll.Get<CtrtContractEntity>(ContractID);                
            }
            else
            {
                lnkbtnSave.Enabled = false;
            }
        }

        protected void lnkbtnSave_Click(object sender, EventArgs e)
        {
            Guid NewContractID = Guid.Empty;
            ContractBll bll = new ContractBll();

            NewContractID = bll.CopyContract(ContractID, txtChangeRemark.Text);

            if (NewContractID == Guid.Empty)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('保存失败！');", true);
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('保存成功!');window.location='ContractAdd.aspx?ContractID="+NewContractID+"';", true);            
            }
        }
    }
}
